package com.ajk.message.model.res;

import java.util.Date;

import org.joda.time.DateTime;

import com.ajk.message.model.BaseModel;
import com.google.gson.annotations.SerializedName;

public class EaseAccessTokenRes extends BaseModel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * token值
	 */
	@SerializedName("access_token")
	private String accessToken;
	
	/**
	 * 有效时间,秒为单位, 默认是七天,在有效期内是不需要重复获取的
	 */
	@SerializedName("expires_in")
	private Integer expiresIn;
	
	/**
	 * 当前app的UUID值
	 */
	@SerializedName("application")
	private String application;
	
	private Date expiresDate;

	public String getAccessToken() {
		return accessToken;
	}

	public void setAccessToken(String accessToken) {
		this.accessToken = accessToken;
	}

	public Integer getExpiresIn() {
		return expiresIn;
	}

	public void setExpiresIn(Integer expiresIn) {
		this.expiresIn = expiresIn;
	}

	public String getApplication() {
		return application;
	}

	public void setApplication(String application) {
		this.application = application;
	}

	public Date getExpiresDate() {
		return expiresDate;
	}

	public void setExpiresDate(Date expiresDate) {
		this.expiresDate = expiresDate;
	}
	
	public boolean isExpires(){
		if(expiresDate==null)
			dealWith();
		if(expiresDate!=null){
			DateTime dTime = new DateTime(expiresDate);
			DateTime now = DateTime.now();
			boolean isExpires = now.isBefore(dTime);
			return isExpires;
		}
		return true;
	}
	
	@Override
	public void dealWith(){
		if(expiresDate==null && expiresIn!=null){
			DateTime dTime = DateTime.now();
			dTime = dTime.plusSeconds(this.expiresIn);
			expiresDate = dTime.toDate();
		}
	}
	
	
}
